import { createRouter, createWebHashHistory } from 'vue-router'

// 引入路由
import routes from './moudles' 

const router = createRouter({
  history: createWebHashHistory(),
  routes
})
router.beforeEach(()=>{
  const w = location.href.indexOf('?');
  const j = location.href.indexOf('#');
  // 如果 # 的位置大于?的位置则代表是第三方授权回调的地址进行特殊处理
  if(w!=-1&&j>w){
    // 获得基础地址
    let baseUrl = location.href.substring(0,w)
    // 获得回调code
    let redirect_code = location.href.substring(w,j)
    // 获得路由地址
    let url = location.href.substring(j)
    // if(url=='/') 
    // let url = '/login'
    // 拼接成完整的url
    let redirect_path = baseUrl + url + redirect_code
    // console.log(url.split('#')[1]+redirect_code,redirect_path);
    console.log(redirect_path,'xxx');
    // 跳转到正确地址
    location.href = redirect_path
  }
  // // 判断是否登录
  // if(to.path === '/mine'&&!localStorage.getItem('token')){
  //   next('/login')
  // }else{
  //   next()
  // }
})
export default router